<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //对象的解构赋值
        let obj = {
            name:'檀健次',
            age:18,
            sex:'男'
        }
        let {name,sex,email} = obj
        console.log(name,sex);  //檀健次  男
        //解构一个不存在的对象，会得到undefined
        console.log(email);  //undefined
        //设置为默认值
        let {hobby='dance'} = obj
        console.log(hobby);

        //数组的解构赋值
        let arr = [1,2]
        let [a,b] = arr
        console.log(a);
        console.log(b);
        //省略前几个数组元素
        let star = ['王鹤棣','成毅','檀健次']
        let [,,tjc] = star
        console.log(tjc);
        //交换两个变量的值
        let x = 10;
        let y = 20;
        [x,y] = [y,x]
        console.log(x,y);
    </script>
</body>
</html>